<template>
  <div class="baseUsage">
      <div class="baseGeneral">
          <div class="title">总基地</div>
          <div class="data blue">{{ sum('unused') + sum('used') || "--" }}</div>
      </div>
      <div class="bcg">
          <img src="/src/assets/baseUsage.png" alt="" class="icon">
      </div>
      <div class="usage">
          <div class="leaveUnused">
              <div class="title">闲置基地</div>
              <div class="data yellow">{{ sum('unused') || "--" }}</div>
          </div>
          <div class="inUse">
              <div class="title">使用中</div>
              <div class="data green">{{ sum('used') || "--"}}</div>
          </div>
      </div>
  </div>
</template>

<script>
import {watch, ref, computed, onMounted} from "vue"
export default {
    name: "baseUsage",
    props:{
      data:{
          type: Object,
          default(){
              return {}
          }
      }
    },
    setup(props, ctx){
        let dataCopy = ref({})

        let sum = computed(() => {
            return type => {
                if(dataCopy.value.baseUsage){
                    return dataCopy.value.baseUsage[type]
                }

            }
        })

        watch(() => props.data, newVal => {
            if(newVal) dataCopy.value = newVal
        }, { deep: true })


        onMounted(() => {

        })

        return {
            dataCopy,
            sum
        }
    }
}
</script>

<style scoped lang="less">
.baseUsage{
  width: 100%;
  height: 100%;
    position: relative;
    display: flex;
    justify-content: space-between;
    align-items: center;
    .baseGeneral, .usage{
        width: 32%;
        text-align: center;
    }
    .usage{
        height: 100%;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: space-evenly;
    }
    .bcg{
        width: 100%;
        height: 100%;
        padding: 10px 0;
        box-sizing: border-box;
        position: absolute;
        z-index: -1;
        left: 0;
        top: 0;
        .icon{
            width: 100%;
            height: auto;
            max-height: 100%;
            object-fit: contain;
            position: relative;
            top: 50%;
            transform: translateY(-50%);
        }
    }
    .title{
        height: fit-content;
        font-size: 16px;
        font-weight: normal;
        color: #AEC3DC;
    }
    .data{
        font-size: 24px;
        font-weight: 500;
        height: 24px;
        line-height: 24px;
        font-family: din;
    }
    .blue{
        color: rgba(84, 188, 255, 1);
    }
    .yellow{
        color: rgba(219, 223, 90, 1);
    }
    .green{
        color: rgba(104, 232, 114, 1);
    }


}
</style>
